#!/bin/bash

set -o errexit

test_dir=$(realpath $(dirname $0))
. ${test_dir}/../functions

set_debug

main() {
	create_infra $namespace
	cluster="some-name-tls-issueref"

	deploy_cert_manager

	desc 'create issuer'
	apply_config "$test_dir/conf/issuer.yml"

	sleep 10

	desc 'create pxc cluster'
	spinup_pxc "$cluster" "$test_dir/conf/$cluster.yml" 3 10 "$conf_dir/secrets_without_tls.yml" "$test_dir/conf/client.yml"
	wait_cluster_consistency "$cluster" 3 2

	desc 'check if certificates issued with certmanager'
	tlsSecretsShouldExist "$cluster-ssl"

	desc 'check if issuer created'
	compare_kubectl clusterissuer/special-selfsigned-issuer

	desc 'check if issuer used during certificate creation'
	compare_kubectl certificate/$cluster-ssl

	destroy $namespace
	desc "test passed"
}

main
